<template>
	<view>
		<input type="text" class="title" placeholder="标题" v-model="this.title" />
		<textarea name="text-content" id="text-content" cols="30" rows="20" v-model="this.body" placeholder="写下你想说的话吧!"></textarea>
		<button class="post-button" type="primary" @click="postContent">发布</button>
	</view>
</template>

<script>
	import {myRequest} from '~@/util/api.js'
	export default {
		data() {
			return {
				title: '',
				body: ''
			}
		},
		methods: {
			postContent(e) {
				myRequest({
					url: 'content',
					header: {
						Authorization: 'token=' + uni.getStorageSync('token')
					},
					method: 'POST',
					data: {
						title: this.title,
						body: this.body,
					}
				}).then((res) => {
					if(res.statusCode == 200){
						uni.showToast({
							title: '发布成功！',
							icon:"success"
						});
						uni.reLaunch({
							url: "/pages/contents/contents"
						});
					}
				})
			}
		}
	}
</script>

<style>
	.uni-file-picker {
		width: 750rpx;
		margin-bottom: 50rpx;
	}
	
	.title {
		width: 750rpx;
		padding: 50rpx;
		border-top: 1px solid lightgrey;
		font-size: 36rpx;
		font-weight: bold;
	}
	
	#text-content {
		width: 750rpx;
		padding: 50rpx;
		border-top: 1px solid lightgray;
		border-bottom: 1px solid lightgray;
		margin-bottom: 50rpx;
		
		box-sizing: border-box;
	}
	
	.post-button {
		width: 500rpx;
		margin: auto;
	}
</style>
